package com.egdigital.allzic.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.actionbarsherlock.app.SherlockFragment;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.egdigital.allzic.R;
import com.egdigital.allzic.ui.activity.ActivityMain;
import com.egdigital.allzic.ui.activity.BaseActivity;

public class FragmentTabExplore extends SherlockFragment implements OnClickListener {

	private static final String	TAG	= FragmentTabExplore.class.getSimpleName();
	//
	private ActivityMain		mParent;
	private RelativeLayout		mLast;
	private RelativeLayout		mAround;
	private RelativeLayout		mDiscover;
	private RelativeLayout		mTop;
	private RelativeLayout		mWorld;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_tab_explore, container, false);
		mLast = (RelativeLayout) view.findViewById(R.id.fragment_explore_last_layout);
		mAround = (RelativeLayout) view.findViewById(R.id.fragment_explore_around_layout);
		mDiscover = (RelativeLayout) view.findViewById(R.id.fragment_explore_discover_layout);
		mTop = (RelativeLayout) view.findViewById(R.id.fragment_explore_top_layout);
		mWorld = (RelativeLayout) view.findViewById(R.id.fragment_explore_world_layout);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		YoYo.with(Techniques.FadeIn).duration(500).playOn(mLast);
		YoYo.with(Techniques.FadeIn).duration(700).playOn(mAround);
		YoYo.with(Techniques.FadeIn).duration(800).playOn(mDiscover);
		YoYo.with(Techniques.FadeIn).duration(900).playOn(mTop);
		YoYo.with(Techniques.FadeIn).duration(1000).playOn(mWorld);
		mLast.setOnClickListener(this);
		mAround.setOnClickListener(this);
		mDiscover.setOnClickListener(this);
		mTop.setOnClickListener(this);
		mWorld.setOnClickListener(this);
		super.onViewCreated(view, savedInstanceState);
	}

	public void onClick(View view) {
		SherlockFragment fragment = null;
		switch (view.getId()) { // click in the menu and send statistics
			case R.id.fragment_explore_last_layout:
				fragment = new FragmentExploreRecent();
				break;
			case R.id.fragment_explore_around_layout:
				fragment = new FragmentExploreAround();
				break;
			case R.id.fragment_explore_discover_layout:
				fragment = new FragmentExploreDiscover();
				break;
			case R.id.fragment_explore_top_layout:
				fragment = new FragmentExploreTop();
				break;
			case R.id.fragment_explore_world_layout:
				fragment = new FragmentCategoryInternational();
				Bundle bundle = new Bundle();
				bundle.putString("title", getString(R.string.fragment_explore_the_world));
				fragment.setArguments(bundle);
				break;
		}
		mParent.mExplorerSelected = true;
		getSherlockActivity().getSupportFragmentManager()
								.beginTransaction()
								.setCustomAnimations(R.anim.slide_in_bottom, R.anim.slide_out_top, R.anim.slide_in_top, R.anim.slide_out_bottom)
								.add(R.id.fragment_explore, fragment)
								.addToBackStack("" + ActivityMain.INDEX_EXPLORE)
								.commit();
	}

	@Override
	public void onAttach(Activity activity) {
		mParent = (ActivityMain) activity;
		super.onAttach(activity);
	}

	@Override
	public void onDetach() {
		mParent = null;
		super.onDetach();
	}
}
